package com.lv.common.widget.textview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import com.lv.common.R

/**
 * 作者： ygx
 * 创建日期：2024/9/30 1:39 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：自定义加粗文字
 */
class MediumTextView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) {

    private var mediumState: Boolean = false
    private var mBold = 0.6f

    init {
        val array = context.obtainStyledAttributes(attrs, R.styleable.MediumTextView)
        mediumState = array.getBoolean(R.styleable.MediumTextView_mediumState, false)
        mBold = array.getFloat(R.styleable.MediumTextView_bold, mBold)
        array.recycle()
    }

    override fun onDraw(canvas: Canvas?) {
        if (mediumState) {
            //可通过设置该数值改变加粗字重
            paint.strokeWidth = mBold
            paint.style = Paint.Style.FILL_AND_STROKE
        }
        super.onDraw(canvas)
    }

    fun setMediumText(mediumText: Boolean, bold: Float = 0.6f) {
        mBold = bold
        this.mediumState = mediumText
        requestLayout()
//        postInvalidate()
    }

}
